#coding=utf-8

from socket import *
import sys
port = int(sys.argv[2])
host = sys.argv[1]
BUF_SIZE = 1024
addr = (host,port)

client_sock = socket(AF_INET,SOCK_STREAM)
client_sock.connect(addr)


while True:
	try:
		data = raw_input('>>')
	except KeyboardInterrupt:
		print('key out')
		data = 'default'
		break
	except SystemError:
		print('sys exit')
	print('input is: %s'%data)
	if data == '':
		if not data:
			print 'empty string'
	elif data == 'exit':
		break
	elif data == None:
		print '发送空数据'
	len = client_sock.send(data*1000)
	print('send: %s len: %d'%(data,len))
	len = client_sock.send(data+'wo')
	print('send: %s len: %d'%(data,len))
#	try:
#		data = client_sock.recv(BUF_SIZE)
#	except:
#		print('keyboard exception')
#		continue
#	if not data:
#		print('exit')
#		break
#	print(data)

client_sock.close()
